From ec72e711561237f10e9e5d41face83a246c10a9e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 13 Feb 2017 09:59:36 -0800 Subject: [PATCH] Rework some required-features tests Don't delete the build dir as this ends up being flaky on Windows. --- tests/required-features.rs | 137 +++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 60 deletions(-) diff --git a/tests/required-features.rs b/tests/required-features.rs index 2b18e03dd..c230ddb19 100644 --- a/tests/required-features.rs +++ b/tests/required-features.rs @@ -23,26 +23,38 @@ fn build_bin_default_features() { name = "foo" required-features = ["a"] "#) - .file("src/main.rs", "fn main() {}"); + .file("src/main.rs", r#" + extern crate foo; + + #[cfg(feature = "a")] + fn test() { + foo::foo(); + } + + fn main() {} + "#) + .file("src/lib.rs", r#" + #[cfg(feature = "a")] + pub fn foo() {} + "#); + p.build(); - assert_that(p.cargo_process("build"), + assert_that(p.cargo("build"), execs().with_status(0)); assert_that(&p.bin("foo"), existing_file()); - assert_that(p.cargo_process("build").arg("--no-default-features"), + assert_that(p.cargo("build").arg("--no-default-features"), execs().with_status(0)); - assert_that(&p.bin("foo"), not(existing_file())); - assert_that(p.cargo_process("build").arg("--bin=foo"), + assert_that(p.cargo("build").arg("--bin=foo"), execs().with_status(0)); assert_that(&p.bin("foo"), existing_file()); - assert_that(p.cargo_process("build").arg("--bin=foo").arg("--no-default-features"), + assert_that(p.cargo("build").arg("--bin=foo").arg("--no-default-features"), execs().with_status(101).with_stderr("\ error: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` ")); - assert_that(&p.bin("foo"), not(existing_file())); } #[test] @@ -62,8 +74,9 @@ fn build_bin_arg_features() { required-features = ["a"] "#) .file("src/main.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("build").arg("--features").arg("a"), + assert_that(p.cargo("build").arg("--features").arg("a"), execs().with_status(0)); assert_that(&p.bin("foo"), existing_file()); } @@ -95,24 +108,22 @@ fn build_bin_multiple_required_features() { "#) .file("src/foo_1.rs", "fn main() {}") .file("src/foo_2.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("build"), + assert_that(p.cargo("build"), execs().with_status(0)); assert_that(&p.bin("foo_1"), not(existing_file())); assert_that(&p.bin("foo_2"), existing_file()); - assert_that(p.cargo_process("build").arg("--features").arg("c"), + assert_that(p.cargo("build").arg("--features").arg("c"), execs().with_status(0)); assert_that(&p.bin("foo_1"), existing_file()); assert_that(&p.bin("foo_2"), existing_file()); - assert_that(p.cargo_process("build").arg("--no-default-features"), + assert_that(p.cargo("build").arg("--no-default-features"), execs().with_status(0)); - - assert_that(&p.bin("foo_1"), not(existing_file())); - assert_that(&p.bin("foo_2"), not(existing_file())); } #[test] @@ -133,17 +144,17 @@ fn build_example_default_features() { required-features = ["a"] "#) .file("examples/foo.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("build").arg("--example=foo"), + assert_that(p.cargo("build").arg("--example=foo"), execs().with_status(0)); assert_that(&p.bin("examples/foo"), existing_file()); - assert_that(p.cargo_process("build").arg("--example=foo").arg("--no-default-features"), + assert_that(p.cargo("build").arg("--example=foo").arg("--no-default-features"), execs().with_status(101).with_stderr("\ error: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` ")); - assert_that(&p.bin("examples/foo"), not(existing_file())); } #[test] @@ -163,8 +174,9 @@ fn build_example_arg_features() { required-features = ["a"] "#) .file("examples/foo.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("build").arg("--example=foo").arg("--features").arg("a"), + assert_that(p.cargo("build").arg("--example=foo").arg("--features").arg("a"), execs().with_status(0)); assert_that(&p.bin("examples/foo"), existing_file()); } @@ -194,8 +206,9 @@ fn build_example_multiple_required_features() { "#) .file("examples/foo_1.rs", "fn main() {}") .file("examples/foo_2.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("build").arg("--example=foo_1"), + assert_that(p.cargo("build").arg("--example=foo_1"), execs().with_status(101).with_stderr("\ error: target `foo_1` requires the features: `b`, `c` Consider enabling them by passing e.g. `--features=\"b c\"` @@ -206,7 +219,7 @@ Consider enabling them by passing e.g. `--features=\"b c\"` assert_that(&p.bin("examples/foo_1"), not(existing_file())); assert_that(&p.bin("examples/foo_2"), existing_file()); - assert_that(p.cargo_process("build").arg("--example=foo_1") + assert_that(p.cargo("build").arg("--example=foo_1") .arg("--features").arg("c"), execs().with_status(0)); assert_that(p.cargo("build").arg("--example=foo_2") @@ -216,7 +229,7 @@ Consider enabling them by passing e.g. `--features=\"b c\"` assert_that(&p.bin("examples/foo_1"), existing_file()); assert_that(&p.bin("examples/foo_2"), existing_file()); - assert_that(p.cargo_process("build").arg("--example=foo_1") + assert_that(p.cargo("build").arg("--example=foo_1") .arg("--no-default-features"), execs().with_status(101).with_stderr("\ error: target `foo_1` requires the features: `b`, `c` @@ -228,9 +241,6 @@ Consider enabling them by passing e.g. `--features=\"b c\"` error: target `foo_2` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` ")); - - assert_that(&p.bin("examples/foo_1"), not(existing_file())); - assert_that(&p.bin("examples/foo_2"), not(existing_file())); } #[test] @@ -251,8 +261,9 @@ fn test_default_features() { required-features = ["a"] "#) .file("tests/foo.rs", "#[test]\nfn test() {}"); + p.build(); - assert_that(p.cargo_process("test"), + assert_that(p.cargo("test"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] @@ -265,16 +276,15 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); - assert_that(p.cargo_process("test").arg("--no-default-features"), + assert_that(p.cargo("test").arg("--no-default-features"), execs().with_status(0).with_stderr(format!("\ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")) .with_stdout("")); - assert_that(p.cargo_process("test").arg("--test=foo"), + assert_that(p.cargo("test").arg("--test=foo"), execs().with_status(0).with_stderr(format!("\ -[COMPILING] foo v0.0.1 ({}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]", p.url())) +[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]")) .with_stdout(" running 1 test test test ... ok @@ -283,7 +293,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); - assert_that(p.cargo_process("test").arg("--test=foo").arg("--no-default-features"), + assert_that(p.cargo("test").arg("--test=foo").arg("--no-default-features"), execs().with_status(101).with_stderr("\ error: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` @@ -307,8 +317,9 @@ fn test_arg_features() { required-features = ["a"] "#) .file("tests/foo.rs", "#[test]\nfn test() {}"); + p.build(); - assert_that(p.cargo_process("test").arg("--features").arg("a"), + assert_that(p.cargo("test").arg("--features").arg("a"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] @@ -347,8 +358,9 @@ fn test_multiple_required_features() { "#) .file("tests/foo_1.rs", "#[test]\nfn test() {}") .file("tests/foo_2.rs", "#[test]\nfn test() {}"); + p.build(); - assert_that(p.cargo_process("test"), + assert_that(p.cargo("test"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] @@ -361,7 +373,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); - assert_that(p.cargo_process("test").arg("--features").arg("c"), + assert_that(p.cargo("test").arg("--features").arg("c"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] @@ -381,7 +393,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); - assert_that(p.cargo_process("test").arg("--no-default-features"), + assert_that(p.cargo("test").arg("--no-default-features"), execs().with_status(0).with_stderr(format!("\ [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")) .with_stdout("")); @@ -415,8 +427,9 @@ fn bench_default_features() { #[bench] fn bench(_: &mut test::Bencher) { }"#); + p.build(); - assert_that(p.cargo_process("bench"), + assert_that(p.cargo("bench"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] release [optimized] target(s) in [..] @@ -429,16 +442,15 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); - assert_that(p.cargo_process("bench").arg("--no-default-features"), + assert_that(p.cargo("bench").arg("--no-default-features"), execs().with_status(0).with_stderr(format!("\ [FINISHED] release [optimized] target(s) in [..]")) .with_stdout("")); - assert_that(p.cargo_process("bench").arg("--bench=foo"), + assert_that(p.cargo("bench").arg("--bench=foo"), execs().with_status(0).with_stderr(format!("\ -[COMPILING] foo v0.0.1 ({}) [FINISHED] release [optimized] target(s) in [..] -[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]", p.url())) +[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]")) .with_stdout(" running 1 test test bench ... bench: [..] 0 ns/iter (+/- 0) @@ -447,7 +459,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); - assert_that(p.cargo_process("bench").arg("--bench=foo").arg("--no-default-features"), + assert_that(p.cargo("bench").arg("--bench=foo").arg("--no-default-features"), execs().with_status(101).with_stderr("\ error: target `foo` requires the features: `a` Consider enabling them by passing e.g. `--features=\"a\"` @@ -481,8 +493,9 @@ fn bench_arg_features() { #[bench] fn bench(_: &mut test::Bencher) { }"#); + p.build(); - assert_that(p.cargo_process("bench").arg("--features").arg("a"), + assert_that(p.cargo("bench").arg("--features").arg("a"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] release [optimized] target(s) in [..] @@ -537,8 +550,9 @@ fn bench_multiple_required_features() { #[bench] fn bench(_: &mut test::Bencher) { }"#); + p.build(); - assert_that(p.cargo_process("bench"), + assert_that(p.cargo("bench"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] release [optimized] target(s) in [..] @@ -551,7 +565,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); - assert_that(p.cargo_process("bench").arg("--features").arg("c"), + assert_that(p.cargo("bench").arg("--features").arg("c"), execs().with_status(0).with_stderr(format!("\ [COMPILING] foo v0.0.1 ({}) [FINISHED] release [optimized] target(s) in [..] @@ -571,7 +585,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured ")); - assert_that(p.cargo_process("bench").arg("--no-default-features"), + assert_that(p.cargo("bench").arg("--no-default-features"), execs().with_status(0).with_stderr(format!("\ [FINISHED] release [optimized] target(s) in [..]")) .with_stdout("")); @@ -600,14 +614,15 @@ fn install_default_features() { "#) .file("src/main.rs", "fn main() {}") .file("examples/foo.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("install"), + assert_that(p.cargo("install"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); - assert_that(p.cargo_process("install").arg("--no-default-features"), + assert_that(p.cargo("install").arg("--no-default-features"), execs().with_status(101).with_stderr(format!("\ [INSTALLING] foo v0.0.1 ([..]) [FINISHED] release [optimized] target(s) in [..] @@ -615,13 +630,13 @@ fn install_default_features() { "))); assert_that(cargo_home(), not(has_installed_exe("foo"))); - assert_that(p.cargo_process("install").arg("--bin=foo"), + assert_that(p.cargo("install").arg("--bin=foo"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); - assert_that(p.cargo_process("install").arg("--bin=foo").arg("--no-default-features"), + assert_that(p.cargo("install").arg("--bin=foo").arg("--no-default-features"), execs().with_status(101).with_stderr(format!("\ [INSTALLING] foo v0.0.1 ([..]) [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ @@ -633,13 +648,13 @@ Consider enabling them by passing e.g. `--features=\"a\"` "))); assert_that(cargo_home(), not(has_installed_exe("foo"))); - assert_that(p.cargo_process("install").arg("--example=foo"), + assert_that(p.cargo("install").arg("--example=foo"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); - assert_that(p.cargo_process("install").arg("--example=foo").arg("--no-default-features"), + assert_that(p.cargo("install").arg("--example=foo").arg("--no-default-features"), execs().with_status(101).with_stderr(format!("\ [INSTALLING] foo v0.0.1 ([..]) [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ @@ -669,11 +684,12 @@ fn install_arg_features() { required-features = ["a"] "#) .file("src/main.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("install").arg("--features").arg("a"), + assert_that(p.cargo("install").arg("--features").arg("a"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); } @@ -704,22 +720,23 @@ fn install_multiple_required_features() { "#) .file("src/foo_1.rs", "fn main() {}") .file("src/foo_2.rs", "fn main() {}"); + p.build(); - assert_that(p.cargo_process("install"), + assert_that(p.cargo("install"), execs().with_status(0)); assert_that(cargo_home(), not(has_installed_exe("foo_1"))); assert_that(cargo_home(), has_installed_exe("foo_2")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); - assert_that(p.cargo_process("install").arg("--features").arg("c"), + assert_that(p.cargo("install").arg("--features").arg("c"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo_1")); assert_that(cargo_home(), has_installed_exe("foo_2")); - assert_that(p.cargo_process("uninstall").arg("foo"), + assert_that(p.cargo("uninstall").arg("foo"), execs().with_status(0)); - assert_that(p.cargo_process("install").arg("--no-default-features"), + assert_that(p.cargo("install").arg("--no-default-features"), execs().with_status(101).with_stderr("\ [INSTALLING] foo v0.0.1 ([..]) [FINISHED] release [optimized] target(s) in [..] -- 2.30.2